package com.feisuanyz.controller;

import com.feisuanyz.dto.EventManagementDTO;
import com.feisuanyz.query.EventManagementQuery;
import com.feisuanyz.service.EventManagementService;
import com.feisuanyz.util.RestResult;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 事件管理控制器
 * @author 23265
 */
@Slf4j
@RestController
@RequestMapping("/event")
@Validated
public class EventManagementController {

    @Autowired
    private EventManagementService eventManagementService;

    @PostMapping("/create")
    public ResponseEntity<RestResult> createEvent(@Valid @RequestBody EventManagementDTO eventManagementDTO) {
        log.info("创建事件请求: {}", eventManagementDTO);
        return ResponseEntity.ok(eventManagementService.createEvent(eventManagementDTO));
    }

    @PutMapping("/update")
    public ResponseEntity<RestResult> updateEvent(@Valid @RequestBody EventManagementDTO eventManagementDTO) {
        log.info("编辑事件请求: {}", eventManagementDTO);
        return ResponseEntity.ok(eventManagementService.updateEvent(eventManagementDTO));
    }

    @DeleteMapping("/delete/{eventId}")
    public ResponseEntity<RestResult> deleteEvent(@PathVariable Integer eventId, @RequestParam Integer updateBy) {
        log.info("删除事件请求: eventId={}, updateBy={}", eventId, updateBy);
        return ResponseEntity.ok(eventManagementService.deleteEvent(eventId, updateBy));
    }

    @GetMapping("/find")
    public ResponseEntity<RestResult> findEvents(@ModelAttribute EventManagementQuery query) {
        log.info("查询事件请求: {}", query);
        return ResponseEntity.ok(eventManagementService.findEvents(query));
    }
}